package chapter07.s03charsteam.p03buffered;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

/**
 * 带缓冲区的包装流
 * 字符流同样提供了带缓冲区的包装流，分别是BufferedReader和BufferedWriter
 *
 */
public class Example17 {
    public static void main(String[] args) throws Exception {
        FileReader reader = new FileReader("src/chapter07/test.txt");
        // 创建一个BufferedReader缓冲对象
        BufferedReader br = new BufferedReader(reader);
        FileWriter writer = new FileWriter("src/chapter07/test2.txt");
        // 创建一个BufferdWriter缓冲区对象
        BufferedWriter bw = new BufferedWriter(writer);
        String str;
        // 每次读取一行文本，判断是否到文件末尾
        while ((str = br.readLine()) != null) {
            bw.write(str);
            // 写入一个换行符，该方法会根据不同的操作系统生成相应的换行符
            bw.newLine();
        }
        br.close();
        bw.close();
    }
}
